﻿using System;
using System.Web.UI.WebControls;
namespace UI.WebControls.ControlsBase
{
    /// <summary>
    /// UI层，页面控件基类，单选列表基类
    /// </summary>
    public class RadioButtonListBase : RadioButtonList
    {
        /// <summary>
        /// 默认选中的值
        /// </summary>
        public string DefaultSelect = string.Empty;
        /// <summary>
        /// 重载基类事件
        /// </summary>
        /// <param name="e"></param>
        protected override void OnLoad(EventArgs e)
        {
            base.RepeatDirection = RepeatDirection.Horizontal;
            base.RepeatLayout = RepeatLayout.Flow;
            if (!string.IsNullOrEmpty(DefaultSelect))
                this.SetSelectValue();
            base.OnLoad(e);
        }
        /// <summary>
        /// 设置默认选中的多选项
        /// </summary>
        private void SetSelectValue()
        {
            foreach (ListItem item in this.Items)
                if (item.Value.Equals(DefaultSelect))
                    item.Selected = true;
        }
        /// <summary>
        /// 获取选中的功能
        /// </summary>
        /// <returns></returns>
        public string GetSelectValue()
        {
            foreach (ListItem item in this.Items)
                if (item.Selected)
                    return item.Value;
            return string.Empty;
        }
    }
}
